package org.loong.crypto.service.core.provider.impl;

import java.util.Collections;
import java.util.Set;

import org.loong.crypto.core.algorithm.SignatureAlgorithm;
import org.loong.crypto.service.core.context.CryptoContext;
import org.loong.crypto.service.core.provider.SignatureProvider;

/**
 * The base abstract class for signature provider.
 */
public abstract class BaseSignatureProvider implements SignatureProvider {

    /**
     * The supported algorithms by the signature provider instance.
     */
    private final Set<SignatureAlgorithm> algs;

    /**
     * The cryptoContext.
     */
    private CryptoContext cryptoContext;
    
    /**
     * Creates a new base signature provider.
     *
     * @param algs The supported algorithms by the signature provider instance.
     */
    public BaseSignatureProvider(final Set<SignatureAlgorithm> algs) {
        if (algs == null) {
            throw new IllegalArgumentException("The supported signature algorithm set must not be null");
        }

        this.algs = Collections.unmodifiableSet(algs);
    }

    @Override
    public Set<SignatureAlgorithm> supportedSignatureAlgorithms() {
        return algs;
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public <T extends CryptoContext> T getCryptoContext() {
        return (T) cryptoContext;
    }

    @Override
    public void setCryptoContext(CryptoContext cryptoContext) {
        this.cryptoContext = cryptoContext;
    }
}
